package com.cryptape.cita_wallet.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.cryptape.cita_wallet.bean.MarkIndexItem;
import com.mangoworld.android.R;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by dengming on 10/3/20.
 */

public class MiningIndexAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>  {
    private List<MarkIndexItem> datas;
    private CloudMinerAdapter.OnItemClickListener onItemClickListener;

    public MiningIndexAdapter(List<MarkIndexItem> datas){
        this.datas = datas;
    }

    public void setDatas(List<MarkIndexItem> datas){
        this.datas = datas;
    }

    public void setOnItemClickListener(CloudMinerAdapter.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new MiningIndexAdapter.ViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_mining_index,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        holder.itemView.setTag(position);
        MiningIndexAdapter.ViewHolder incomeHolder = ((MiningIndexAdapter.ViewHolder)holder);
        MarkIndexItem bean = datas.get(position);
        incomeHolder.tv_income_time.setText(bean.getCreateTime());
        String num = bean.getNum();
        if(num != null){
            BigDecimal data = new BigDecimal(num);
            if(data.compareTo(BigDecimal.ZERO)>0){
                incomeHolder.tv_income_amount.setText("+"+num);
            }else{
                incomeHolder.tv_income_amount.setText(num);
            }
        }
//        ((ClountMinerViewHolder)holder).btn_buy.setTag(new Integer(position));
    }

    @Override
    public int getItemCount() {
        return datas == null?0:datas.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView tv_income_time;
        TextView tv_income_amount;

        public ViewHolder(View view) {
            super(view);
            tv_income_time = view.findViewById(R.id.tv_income_time);
            tv_income_amount  = view.findViewById(R.id.tv_income_amount);
        }
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }
}
